<?php
    @session_start();
    @include_once '../app/connection.php';
    include 'check_user.php';
    
	if($is_sv)
	{
		$sql = mysql_query("SELECT * FROM hocky WHERE HOCKY=(SELECT MAX(HOCKY) FROM hocky WHERE NAM=(SELECT MAX(NAM) FROM hocky))
			AND NAM=(SELECT MAX(NAM) FROM hocky)");
		$row = mysql_fetch_array($sql);
		echo $row['HOCKY']."<br/>".$row['NAM'];
		
		$today = date("Y-m-d");    
		$dangkymh = false;
		if($today >= $row['NGAYMODANGKY'] && $today <= $row['NGAYDONGDANGKY'])
			$dangkymh = true; 
		$hieuchinhhp = false;
		if($today >= $row['NGAYMOHIEUCHINH'] && $today <= $row['NGAYDONGHIEUCHINH'])
			$hieuchinhhp = true;    
		if(!$dangkymh) echo "<br/> dang ky mon hoc: ".$dangkymh;
		else if(!$hieuchinhhp) "<br/> hieu chinh: ".$hieuchinhhp;
		if($dangkymh) {
				
				echo $_SESSION['s_user'];
				
				$sql = mysql_query("SELECT * FROM dangky WHERE MSSV='".$_SESSION['s_user']."'");            
				
				if(mysql_num_rows($sql) == 0) {
					header("Location: index.php?page=dkmh");
					//echo "<meta http-equiv=\"refresh\" content=\"0;URL=?page=dkmh\">";
				}
				else header("Location: ?page=trangthai_dkmh");
		}
		//else header("location: ../index.php");
		if($hieuchinhhp)
		{
				$u = $_SESSION['s_user'];
				$s = mysql_query("SELECT * FROM dangky WHERE MSSV='".$u."'");
				/*$msv = "";
				while($r = mysql_fetch_array($s))
				{
					$msv .= $r['MSSV'].";";
				}*/
				
				if(mysql_num_rows($s) == 0) {
					header("Location: index.php?page=dkmh");
					//echo "<meta http-equiv=\"refresh\" content=\"0;URL=?page=dkmh\">";
				}
				else header("Location: ?page=trangthai_dkmh");
				
				/*if(preg_match("/".$u."/",$msv) == 1)
				{
					 header("Location: ?page=dkmh");
				}
				else if(preg_match("/".$u."/",$msv) == 0)
				{
					header("Location: ?page=trangthai_dkmh");
				}*/
		}
	}
	else
	{
		echo "Bạn không có quyền truy cập trang này!";
		echo "<meta http-equiv=\"refresh\" content=\"2; URL=index.php\">";
	}
    /*function check_sv() {
        
        if(isset($_SESSION['s_user'])) {
            
            $user = $_SESSION['s_user'];
            $pos = "GV";
			$kq = strpos($user,$pos);
            
			if($kq === false)
                return true;            
        }
        else return false;            
    }*/
	ob_flush();
?>